//
//  main.m
//  lzl5-18
//
//  Created by 刘振霖 on 16/5/23.
//  Copyright © 2016年 lzl. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // insert code here...
        NSLog(@"Hello, World!");
        NSString *baseURL = @"http://127.0.0.1:3000/";
//        NSDictionary *params = @{
//                                 @"wd":@"help",
//                                 };
//        NSMutableArray *arr = [NSMutableArray new];
//        __block int i = 0;
//        [params enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *obj, BOOL *stop) {
//            NSString *str = [NSString stringWithFormat:@"%@=%@",key, obj];
//            [arr addObject:str];
//            i += 1;
//        }];
//
//        NSString *res = [arr componentsJoinedByString:@"&"];
//        res = [res stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
//        res = [NSString stringWithFormat:@"%@?%@", baseURL, res];
//        NSLog(@"%@",res);
        
    NSURL *url = [NSURL URLWithString:baseURL];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    NSError *err;
    NSHTTPURLResponse *response;
    NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&err];
        if (err) {
            NSLog(@"%@",err);
        }
    NSLog(@"status:%ld",response.statusCode);
    NSLog(@"%@",response.allHeaderFields);
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"size:%lu", data.length);
    NSLog(@"%@",str);
        
        
        
    }
    return 0;
}
